package homework0718;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class test {
    public static void main(String[] args) {
        documentCopy();
        documentAdd();
    }

    public static void documentCopy() {
        FileInputStream fisIn = null;
        FileOutputStream fisOut = null;
        try {
            fisIn = new FileInputStream("C:/a.txt");
            int d = 0;
            fisOut = new FileOutputStream("C:/b.txt");
            while ((d=fisIn.read()) != -1) {
                fisOut.write((char)d);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fisIn != null || fisOut != null) {
                try {
                    fisOut.close();
                    fisIn.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }


    }

    public static void documentAdd() {
        Scanner scanner = new Scanner(System.in);
        FileOutputStream fisOut = null;
        try {
            System.out.println("请输入想追加的内容");
            String str1 = scanner.next();


            fisOut = new FileOutputStream("C:/a.txt",true);


            fisOut.write(str1.getBytes());


        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if ( fisOut != null) {
                try {
                    fisOut.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }




    }
}
